package demo.msa.hello.server;

import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
public class SayController {

    @GetMapping("/say1")
    public String say1(@RequestParam("name") String name) {
        return "hello " + name;
    }

    @GetMapping("/say2/{name}")
    public String say2(@PathVariable("name") String name) {
        return "welcome. " + name;
    }

    @GetMapping("/say3")
    public String say3(@RequestHeader("name") String name) {
        return "well done! " + name;
    }

    @GetMapping("/say4")
    public List say4() {
        List list = new ArrayList();
        list.add("item1");
        list.add("item2");
        list.add("item3");
        return list;
    }

    @GetMapping("/say5")
    public List say5(@RequestParam("name") String[] name) {
        List list = Arrays.asList(name);
        return list;
    }

    @GetMapping("/say6")
    public Map say6(@RequestParam("name") String name, @RequestParam("age") int age) {
        Map map = new HashMap<String, Object>();
        map.put("name", name);
        map.put("age", age);

        return map;
    }

    @GetMapping("/say7")
    public Person say7(@RequestParam("name") String name, @RequestParam("age") int age) {
        Person person = new Person(name,age);

        return person;
    }
}
